package cn.jinjimi.domain.data.net;

import cn.jinjimi.app.custom.entity.CustomFollowsDTO;
import cn.jinjimi.app.custom.entity.CustomListDTO;
import cn.jinjimi.app.custom.entity.Insurance;
import cn.jinjimi.domain.data.dto.ClueDTO;
import cn.jinjimi.domain.data.dto.ClueStatisticDTO;
import cn.jinjimi.domain.data.dto.CustomImportDTO;
import cn.jinjimi.domain.data.dto.CustomLastedFollowDTO;
import cn.jinjimi.domain.data.dto.CustomTagDTO;
import cn.jinjimi.domain.data.dto.CustomerDto;
import cn.jinjimi.domain.data.dto.CustomerTypeDto;
import cn.jinjimi.domain.data.dto.CustomerUpdateDto;
import cn.jinjimi.domain.data.dto.FollowDto;
import cn.jinjimi.domain.data.dto.InsuranceDto;
import cn.jinjimi.domain.data.dto.ProposalDTO;
import cn.jinjimi.domain.data.dto.TransferCustomDTO;
import cn.jinjimi.app.entity.PhotoList;

import java.util.HashMap;
import java.util.List;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Path;
import retrofit2.http.Query;

/**
 * Created by zhenhua on 16/7/20.
 */
public interface CustomerService {

    @POST("/app/customer")
    @Multipart
    Call<CustomerDto> addCustomer(@PartMap HashMap<String, RequestBody> data,
                                  @Query("clue_id") String clueId);

    @PUT("/app/customer/{customerId}")
    Call<CustomerDto> updateCustomer(@Path("customerId") String customerId,
                                     @Body CustomerUpdateDto dto);

    @GET("/app/customer/{customerId}")
    Call<CustomerDto> getCustomer(@Path("customerId") String customerId);


    @GET("/app/customer")
    Call<CustomListDTO> getCustomerList(@Query("lastmodified") long lastModifiedTime);

    /**
     * 删除客户
     *
     * @param customerId
     * @return
     */
    @DELETE("/app/customer/{customerId}")
    Call<CustomerDto> deleteCustomer(@Path("customerId") String customerId);


    @PUT("/app/customer/{customerId}")
    Call<CustomerDto> updateCustomerType(@Path("customerId") String customerId,
                                         @Body CustomerTypeDto dto);

    /**
     * 获取客户的标签
     *
     * @return
     */
    @GET("/app/customer/labels")
    Call<CustomTagDTO> getCustomerTags();


    /**
     * 删除跟进记录
     *
     * @param customerId
     * @param followId
     * @return
     */
    @DELETE("/app/customer/{customerId}/follows/{followId}")
    Call<ResponseBody> deleteFollowRecord(@Path("customerId") String customerId,
                                          @Path("followId") String followId);

    @DELETE("/app/customer/{customerId}/attachments/{attachmentId}")
    Call<ResponseBody> deleteCustomerAttachment(@Path("customerId") String customerId,
                                                @Path("attachmentId") String attachmentId);


    @DELETE("/app/customer/follows/{followId}/attachments/{attachmentIds}")
    Call<ResponseBody> deleteFollowAttachment(@Path("followId") String followId,
                                              @Path("attachmentIds") String attachmentIds);


    /**
     * 获取客户的跟进记录
     *
     * @param customerId
     * @return
     */
    @GET("/app/customer/follows/history/{customerId}")
    Call<CustomFollowsDTO> getFollows(@Path("customerId") String customerId);

    /**
     * 获取客户资料的附件列表
     *
     * @param customerId
     * @return
     */
    @GET("/app/customer/{customerId}/attachments")
    Call<PhotoList> getAttachments(@Path("customerId") String customerId);


    /**
     * 更新更近记录
     *
     * @param customerId
     * @param followId
     * @param content
     * @param followTime
     * @return
     */
    @PUT("/app/customer/{customerId}/follows")
    Call<FollowDto> updateFollow(@Path("customerId") String customerId,
                                 @Query("id") String followId,
                                 @Query("content") String content,
                                 @Query("followTime") String followTime);

    /**
     * 创建更近记录
     *
     * @param customerId
     * @param content
     * @param followTime
     * @return
     */
    @POST("/app/customer/{customerId}/follows")
    Call<FollowDto> addFollow(@Path("customerId") long customerId,
                              @Query("customerId") long cutomerId,
                              @Query("content") String content,
                              @Query("followTime") long followTime);


    @DELETE("/app/customer/{customerId}/policies/{policyId}")
    Call<Insurance> deleteInsurance(@Path("customerId") String customerId,
                                    @Path("policyId") String insuranceId);

    @POST("/app/customer/{customerId}/policies")
    Call<Insurance> addInsurance(@Path("customerId") String customerId,
                                 @Body InsuranceDto dto);

    @GET("/app/customer/{customerId}/policies")
    Call<Insurance> getInsuranceList(@Path("customerId") String customerId);


    @PUT("/app/customer/{customerId}/policies/{policyId}")
    Call<Insurance> updateInsurance(@Path("customerId") String customerId,
                                    @Path("policyId") String insuranceId,
                                    @Body InsuranceDto dto);


    @GET("/app/customer/{customerId}/policies/{policyId}")
    Call<Insurance> getInsurance(@Path("customerId") String customerId,
                                 @Path("policyId") String policyId);


    @POST("/app/customer/import")
    @Multipart
    Call<CustomImportDTO> addContacts(@Part List<MultipartBody.Part> parts);

    /**
     * 获取客户线索列表
     *
     * @param page
     * @return
     */
    @GET("bxr/crm/clues")
    Call<ClueDTO> getClues(@Query("page") int page,
                           @Query("source") String source);

    /**
     * 客户线索统计
     *
     * @return
     */
    @GET("bxr/crm/clues/statistics")
    Call<ClueStatisticDTO> getClueStatistics();

    /**
     * 最近跟进客户列表
     *
     * @return
     */
    @GET("bxr/app/customer/recent_follows")
    Call<CustomLastedFollowDTO> getLastedFollows(@Query("page") int page,
                                                 @Query("limit") int limit);

    /**
     * 客户计划书列表
     *
     * @param customId
     * @return
     */
    @GET("/app/customer/{customerId}/proposals")
    Call<ProposalDTO> getProposals(@Path("customerId") String customId,
                                   @Query("page") int page,
                                   @Query("limit") int limit);

    @PUT("/crm/clues/{clue_id}/transfer/customers/{customer_id}")
    Call<TransferCustomDTO> transferCustom(@Path("clue_id") String clueId,
                                           @Path("customer_id") String customiD);
}
